package com.yvan.periscope.dto.request;

import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;
import org.joda.time.DateTime;

import java.io.Serializable;

/**
 * 作者： lzw<br/>
 * 创建时间：2018-09-10 15:04 <br/>
 */
@Data
public class SummaryReq implements Serializable {

    @ApiModelProperty(value = "分组时间间隔 (hour|day|...)", example = "day")
    private String groupBy;

    @ApiModelProperty("起始时间")
    private DateTime min;

    @ApiModelProperty("结束时间")
    private DateTime max;

    /**
     * 设置默认参数逻辑
     */
    public void defaultParam() {
        if (this.getMin() == null && this.getMax() == null) {
            DateTime now = DateTime.now();
            this.setMin(now.plusDays(-1).withTimeAtStartOfDay());
            this.setMax(now.withTime(23, 59, 59, 999));
        }
        if (StringUtils.isBlank(this.getGroupBy())) {
            this.setGroupBy("day");
        }
    }
}
